var pagePaging = function (config) {
            var _self = this;
            _self.config = $.extend({},pagePaging.config,config);
            _self.global = {

            };
            _self._init();
        };
        pagePaging.config={
            parentCls : '.paging-page',
            pageTotal : 10,
            pageSingle : 10,
            maxPageIndex : 13,
            currentPageIndex : 1,
            pageChangeCallback : ''
        };
        pagePaging.prototype ={
            _reset:function(index,total){
                var _self  = this;
                _self.config.currentPageIndex = index;
                _self.config.pageTotal = total;
                _self._pagingRender();
            },
            _init : function () {
                var _self = this;

                _self._pagingRender();
//                    _self._pagingRender_test();
                $(document).on('click','.page-items', function (e) {
                    var currentTarget = $(e.currentTarget);
                    _self.config.currentPageIndex = parseInt(currentTarget.html(),10);
                    _self.config.pageChangeCallback && _self.config.pageChangeCallback(_self.config.currentPageIndex);
                    _self._pagingRender();
                });

                $(document).on('click','.page-prev', function () {
                    _self.config.currentPageIndex--;
                    _self.config.pageChangeCallback && _self.config.pageChangeCallback(_self.config.currentPageIndex);
                    _self._pagingRender();
                });
                $(document).on('click','.page-next', function () {
                    _self.config.currentPageIndex++;
                    _self.config.pageChangeCallback && _self.config.pageChangeCallback(_self.config.currentPageIndex);
                    _self._pagingRender();
                });

                //解决双击选择文案的bug
                $(document).on('selectstart','.page-num', function () {
                    return false;
                })


            },
            _pagingRender: function () {
                var _self = this;
                _self.config.currentPageIndex = _self.config.currentPageIndex > _self.config.pageTotal ? _self.config.pageTotal : _self.config.currentPageIndex; //传入的页数超过总页数,则显示最后一页
                _self.config.currentPageIndex = _self.config.currentPageIndex < 1 ? 1 : _self.config.currentPageIndex;//传入的页数小于1,则显示第一页
                var prevPage =  _self.config.currentPageIndex == 1 ?  '<dd class="page-num page-arrow"> 上一页 </dd>' :  '<dd class="page-num page-arrow page-prev"> 上一页 </dd>';
                var nextPage =  _self.config.currentPageIndex == _self.config.pageTotal ?  '<dd class="page-num page-arrow"> 下一页 </dd>' : '<dd class="page-num page-arrow page-next"> 下一页 </dd>';
                var pagePagingHtml = '';
                $(_self.config.parentCls).html('');//重置分页样式

                var afterStartPage = _self.config.currentPageIndex;
                if(_self.config.pageTotal <= 1){//只有一页,不需要分页
                    return false;
                }else if(_self.config.pageTotal <= _self.config.maxPageIndex){//总页数小于等于可显示页数
                    pagePagingHtml = _self._getPageHtml(1,_self.config.pageTotal);
                }else{
                    var middlePage = Math.floor(_self.config.maxPageIndex / 2);
                    var beforeHtml = '';
                    var pageOmit = '<dd class="page-num "> ... </dd>';
                    var lastPage = '<dd class="page-num page-items">' + _self.config.pageTotal + '</dd>';
                    var afterHtml = '';

                    if(_self.config.currentPageIndex > middlePage) { //如果当前页面大于一屏可放页数的中间值
                        var afterNum = _self.config.currentPageIndex + middlePage;
                        if( afterNum < _self.config.pageTotal ){
                            var afterEnd = (middlePage - 2) + _self.config.currentPageIndex; //减去最后一页和省略号的位置+当前位置,就是结束位置
                            afterHtml = _self._getPageHtml(_self.config.currentPageIndex,afterEnd) + pageOmit + lastPage ;
                        }else if(afterNum == _self.config.pageTotal){
                            afterHtml =  _self._getPageHtml(_self.config.currentPageIndex,_self.config.pageTotal)  ;
                        }else{
                            var afterDiff = afterNum - _self.config.pageTotal;
                            afterStartPage = _self.config.currentPageIndex - afterDiff;
                            afterHtml = _self._getPageHtml(afterStartPage,_self.config.pageTotal)
                        }

                        afterStartPage--;//当前开始的那个已经渲染,需要去掉
                        if(afterStartPage - middlePage >= 1 ){
                            var beforeStart = (afterStartPage - middlePage) + 2;
                            beforeHtml =  pageOmit +  _self._getPageHtml(beforeStart,afterStartPage)
                        }else if(afterStartPage - middlePage == 0){
                            beforeHtml = _self._getPageHtml(1,afterStartPage)
                        }
                        pagePagingHtml = beforeHtml + afterHtml;
                    }else{
                        var afterEndPage = _self.config.maxPageIndex - 2;
                        beforeHtml = _self._getPageHtml(1,afterEndPage);
                        pagePagingHtml = beforeHtml + pageOmit + lastPage;
                    }
                }

                $(_self.config.parentCls).html(prevPage + pagePagingHtml + nextPage)

            },
            _getPageHtml : function (start,end) {
                var _self = this;
                var pageNumHtml = '';
                end++;
                for(var i = start; i < end ;i++){
                    if(i == _self.config.currentPageIndex){
                        pageNumHtml += '<dd class="page-num page-sub">' + i + '</dd>';
                    }else{
                        pageNumHtml += '<dd class="page-num page-items">' + i + '</dd>';
                    }
                }
                return pageNumHtml;
            }
        };